package net.qiqb.core.executing.definition;

import lombok.extern.slf4j.Slf4j;
import net.qiqb.core.executing.annotation.AggregateObjectPostProcessor;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@Slf4j
public class AggregateObjectPostProcessorRegistrar {


    private final List<AggregateObjectPostProcessor> cache = new ArrayList<>();


    public void addAll(Collection<AggregateObjectPostProcessor> aggregateObjectPostProcessors) {

        cache.addAll(aggregateObjectPostProcessors);
    }


    public List<AggregateObjectPostProcessor> matchAggregateObjectPostProcessors(Class<?> aggregateRootClass) {
        List<AggregateObjectPostProcessor> matched = new ArrayList<>();
        for (AggregateObjectPostProcessor aggregateObjectPostProcessor : cache) {
            if (aggregateObjectPostProcessor.matched(aggregateRootClass)) {
                matched.add(aggregateObjectPostProcessor);
            }
        }
        return matched;
    }

}
